package StudyCode.summary.mydatetime;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class AdjustingDatesAndTimes {
	public static void main(String[] args) {
		LocalDate today = LocalDate.now();
		System.out.println("今天: " + today);

		// 使用DateAdjuster将今天的日期调整到下周一
		LocalDate nextMonday = today.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
		System.out.println("下周一: " + nextMonday);

		// 使用 TemporalAdjuster 将今天的日期调整为月的最后一天
		LocalDate lastDayOfMonth = today.with(TemporalAdjusters.lastDayOfMonth());
		System.out.println("这个月最后一天: " + lastDayOfMonth);

		// 创建一个在3个月2天后日期的 TemporalAdjuster
		TemporalAdjuster adjuster = TemporalAdjusters.ofDateAdjuster((LocalDate date) -> date.plusMonths(3).plusDays(2));
		LocalDate dayAfter3Mon2Day = today.with(adjuster);
		System.out.println("三月零两天后的日期: " + dayAfter3Mon2Day);
	}
}
